﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Audio;

namespace MiaProject
{
    class Tower : Actor 
    {
        public Tower(): base()
        {   
            this.rotation = 3.0f;
            this.scale = 0.5f;
            this.tiroFrequence = 0.1f;
            this.distTargetAtack = 1000;
            this.status = true;
            
        }
        public void update(GameTime gameTime)
        {
            Player p = Player.getInstance();
            if (!this.status)
            {
                this.updateTiro(gameTime, p.pos);
                return;
            }
            Vector3 v = p.pos - this.pos;
            Vector3 u = new Vector3(1,0,0);
            //u.Normalize();

            v.Y = 0;
            v.Normalize();

            float dp = Vector3.Dot(u, v); //dot product
            if (dp > 1.0) dp = 1.0f;
            if (dp < -1.0) dp = -1.0f;

            //verificar side 
            //this.rotation = (1.5f+(float)Math.Acos(dp))*this.side(u,v);
            if(this.side(u, v)>0)
                this.rotation = -1.6f - (float)Math.Acos(dp);
            else//
                this.rotation = 4.7f + (float)Math.Acos(dp);


            this.updateTiro(gameTime,p.pos);
            
        }
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        public void draw(Matrix view, Matrix projection,BoundingFrustum frustum)
        {
            this.drawActor(view, projection,frustum);
            this.drawTiroScale(view, projection,this.scaleTiro);
        }
    }
}
